import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:whitesdk/whitesdk.dart';

class WhiteBoard extends StatefulWidget {
  WhiteBoard({Key key}) : super(key: key);

  @override
  _WhiteBoardState createState() => _WhiteBoardState();
}

class _WhiteBoardState extends State<WhiteBoard> {

  String appId = "283/VGiScM9Wiw2HJg";
  String uuid = "8c1b45501f3411eb9d2be9bc8750e1f1";
  String roomToken = "NETLESSROOM_YWs9M2R5WmdQcFlLcFlTdlQ1ZjRkOFBiNjNnY1RoZ3BDSDlwQXk3Jm5vbmNlPTE2MDQ1NTk2MTk3OTAwMCZyb2xlPTAmc2lnPWRmOTQwZjJmYzE1YzZlMjZkYzQwOGNhMDc0ZGNiNTIzOTcyMjA5MTNiNjgxNzlmODM1ZDAyMDAyNjVkNTlhOTkmdXVpZD04YzFiNDU1MDFmMzQxMWViOWQyYmU5YmM4NzUwZTFmMQ";
  int viewId;
  WhiteBoardSdk sdk;
  WhiteBoardSdkRoom room;

  @override
  void initState() { 
    super.initState();
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeLeft,
      DeviceOrientation.landscapeRight
    ]);
  }

  @override
  void dispose() { 
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown
    ]);
    super.dispose();
  }

  

  createWhiteboardSdk() async {
    this.sdk = WhiteBoardSdk(
      WhiteBoardSdkConfiguration(viewId, appId, true)
    );
    this.room = await this.sdk.joinRoom(
      RoomParams(uuid,roomToken)
    );
    this.setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(color: Colors.blue),
       child: WhiteBoardSdkPlatformView(
         onWhiteBoardSdkPlatformViewCreated: (int viewId) {
           this.viewId = viewId;
           createWhiteboardSdk();
         },
       ),
    );
  }
}